package park.gz.com.parkingfee.bean;

import android.content.Context;
import android.util.Log;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.DbManager;
import org.xutils.ex.DbException;
import org.xutils.x;

import java.util.List;

import park.gz.com.parkingfee.activity.MyAppcation;

/**
 * Created by Administrator on 2017-03-20.
 */

public class DBBean {
    public static DbManager db = x.getDb(MyAppcation.daoConfig);
    public static void savetodbUserInfo(Context context, String itemresult){

        try {
            db.delete(UserBean.class);
            JSONArray array=new JSONArray(itemresult);
            for (int i = 0; i < array.length(); i++) {
                JSONObject jsonObject=new JSONObject(array.get(i).toString().trim());
                UserBean userBean=new UserBean();
                userBean.setId(jsonObject.getString("id"));
                userBean.setLogin(jsonObject.getString("login"));
                userBean.setPassword(jsonObject.getString("password"));
                userBean.setUsertype(jsonObject.getString("user_type"));
                userBean.setStatus(jsonObject.getString("status"));
                userBean.setCreated_at(jsonObject.getString("created_at"));
                userBean.setUpdated_at(jsonObject.getString("updated_at"));
                db.save(userBean);
            }
        } catch (DbException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    public static List<UserBean> getUserinfo(){
        try {
            List<UserBean> userlist = db.selector(UserBean.class).findAll();
            return userlist;
        } catch (DbException e) {
            e.printStackTrace();
        }
        return null;
    }

}
